using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EM.Repository.utility;

namespace EM.Common
{
    public partial class SectionName : System.Web.UI.UserControl
    {
        public string APPROOT = "";
        public int PAGESECTIONID_ = 0;
        public string SECTIONNAME = "";
        public string SHORTDESC = "";
        public string PAGE_WIDTH = "";
        public string CONTENTID = "";
        protected string ADD_SUBJECT = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            AppPathFinder AppPath = new AppPathFinder();
            APPROOT = AppPath.GetApplicationPath();
            Authentication ua = new Authentication();
            if (ua.hasSessionAuthentication())
            {
                setSectionName();
            }
        }

        private void setSectionName()
        {
            DbHelper Dsrv = new DbHelper();
            SqlCommand Cmd = new SqlCommand();
            DataTable Dt = new DataTable();
            string sSQL = "";

            sSQL = "";
            sSQL += " SELECT A.PAGESECTIONID, A.CONTENTID, PSL.SECTIONNAME, PSL.SHORTDESC";
            sSQL += " FROM 	(";
            sSQL += " 	    SELECT PAGESECTIONID, CONTENTID";
            sSQL += " 	    FROM TBLPAGESECTION";
            sSQL += " 	    WHERE PAGESECTIONID = @PAGESECTIONID";
            sSQL += " )A, TBLPAGESECTION_L PSL";
            sSQL += " WHERE 1 = 1";
            sSQL += " AND A.PAGESECTIONID = PSL.PAGESECTIONID";
            sSQL += " AND PSL.LANGCODE = @LANGCODE ";

            Cmd.Parameters.Add("@PAGESECTIONID", SqlDbType.Int).Value = PAGESECTIONID_;
            Cmd.Parameters.Add("@LANGCODE", SqlDbType.NVarChar).Value = Session["LANGCODE"].ToString(); //Session["LANGCODE"].ToString();
            Cmd.CommandText = sSQL;

            Dt = Dsrv.GetDataTable(Cmd, "TBLPAGENAME");

            if (Dt.Rows.Count > 0)
            {
                SECTIONNAME = Dt.Rows[0]["SECTIONNAME"].ToString();
                SHORTDESC = Dt.Rows[0]["SHORTDESC"].ToString();
                CONTENTID = Dt.Rows[0]["CONTENTID"].ToString();

                if (CONTENTID != "")
                {
                    //imgHelpIcon.Visible = true;
                    //imgHelpIcon.Attributes["onclick"] = "openContentWin('" + APPROOT + "/Content/default.aspx?cttid=" + CONTENTID + "')";

                    //lblHelpIcon.Text = "<img id=\"imgHelpIcon\" runat=\"server\" alt=\"\" src=\"~/images/info_page.jpg\" style=\"cursor:pointer;\" ";
                    //lblHelpIcon.Text += " onclick=\"openContentWin('" + APPROOT + "/Content/default.aspx?cttid=" + CONTENTID + " \" />";

                    lblHelpIcon.Text = "<img id=\"imgHelpIcon\" runat=\"server\" alt=\"\" src=\"" + APPROOT + "/images/info_page.jpg\" style=\"cursor:pointer;\" ";
                    lblHelpIcon.Text += " onclick=\"openContentWin('" + APPROOT + "/Content/default.aspx?cttid=" + CONTENTID + "')\" /> ";
                }
                else
                {
                    //imgHelpIcon.Visible = false;
                    lblHelpIcon.Text = "&nbsp;";
                }

                if (SHORTDESC != "")
                {
                    trSectionNameDesc.Visible = true;
                    //srvDivSectionNameDesc.Attributes["style"] = "width:" + PAGE_WIDTH;
                }
                else
                {
                    trSectionNameDesc.Visible = false;
                }

                if (ADD_SUBJECT != "")
                {
                    SECTIONNAME += ": " + ADD_SUBJECT;
                }

            }
        }

        public int PAGESECTIONID
        {
            get { return PAGESECTIONID_; }
            set { PAGESECTIONID_ = value; }
        }

        public string PAGEWIDTH
        {
            get { return PAGE_WIDTH; }
            set { PAGE_WIDTH = value; }
        }

        public string ADDSUBJECT
        {
            get { return ADD_SUBJECT; }
            set { ADD_SUBJECT = value; }
        }
    }
}